<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下载安装包 - 导航服务</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: #f8f9fa;
            min-height: 100vh;
            padding: 20px;
            color: #333;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        header {
            text-align: center;
            margin-bottom: 40px;
            color: #333;
        }

        h1 {
            font-size: 2.2rem;
            margin-bottom: 10px;
            font-weight: 600;
            color: #2c3e50;
        }

        h2 {
            color: #333;
            margin-bottom: 15px;
        }

        h3 {
            color: #555;
            margin-bottom: 10px;
        }

        .download-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .download-card {
            background: white;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            padding: 20px;
            transition: border-color 0.2s ease;
            overflow: hidden;
        }

        .download-card:hover {
            border-color: #007bff;
        }

        .platform-icon {
            font-size: 2rem;
            margin-bottom: 15px;
            text-align: center;
            color: #6c757d;
        }

        .platform-name {
            font-size: 1.1rem;
            font-weight: 600;
            margin-bottom: 8px;
            color: #2c3e50;
        }

        .platform-desc {
            color: #6c757d;
            margin-bottom: 15px;
            line-height: 1.5;
            font-size: 14px;
        }

        .download-info {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 4px;
            margin-bottom: 15px;
        }

        .download-info h4 {
            margin-bottom: 10px;
            color: #2c3e50;
            font-weight: 600;
            font-size: 14px;
        }

        .download-info ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .download-info li {
            padding: 4px 0;
            color: #6c757d;
            font-size: 13px;
        }

        .download-info li:before {
            content: '✓ ';
            color: #28a745;
            font-weight: bold;
        }

        .download-btn {
            display: inline-block;
            padding: 10px 20px;
            background: #007bff;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-weight: 500;
            transition: background-color 0.2s ease;
            border: none;
            cursor: pointer;
            width: 100%;
            text-align: center;
            font-size: 14px;
        }

        .download-btn:hover {
            background: #0056b3;
            color: white;
            text-decoration: none;
        }

        .download-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }

        .file-size {
            font-size: 12px;
            color: #6c757d;
            margin-top: 8px;
            text-align: center;
        }

        .instructions {
            background: white;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            padding: 20px;
            margin-bottom: 20px;
        }

        .instructions h2 {
            margin-bottom: 20px;
            color: #2c3e50;
            text-align: center;
            font-size: 1.5rem;
            font-weight: 600;
        }

        .instructions h3 {
            margin: 20px 0 10px 0;
            color: #555;
            font-size: 1.1rem;
            font-weight: 600;
        }

        .instructions ol {
            padding-left: 20px;
            line-height: 1.6;
        }

        .instructions li {
            margin-bottom: 8px;
            color: #666;
            font-size: 14px;
        }

        .back-btn {
            display: inline-block;
            padding: 10px 20px;
            background: #6c757d;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-weight: 500;
            transition: background-color 0.2s ease;
            border: none;
            cursor: pointer;
            font-size: 14px;
        }

        .back-btn:hover {
            background: #5a6268;
            color: white;
            text-decoration: none;
        }

        .status-indicator {
            display: inline-block;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            margin-right: 8px;
        }

        .status-ready {
            background: #28a745;
        }

        .status-building {
            background: #ffc107;
        }

        .status-error {
            background: #dc3545;
        }

        @media (max-width: 768px) {
            .header h1 {
                font-size: 2rem;
            }
            
            .download-grid {
                grid-template-columns: 1fr;
                gap: 20px;
            }
            
            .download-card {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>📦 下载安装包</h1>
            <p>选择适合您系统的版本进行下载</p>
            <a href="/" class="back-btn">← 返回首页</a>
        </header>

        <div class="download-grid">
            <!-- macOS ARM64 -->
            <div class="download-card">
                <div class="platform-icon">🍎</div>
                <div class="platform-name">macOS (ARM64)</div>
                <div class="platform-desc">适用于 Mac M1/M2/M3 芯片的 Mac 电脑</div>
                <div class="download-info">
                    <h4>系统要求</h4>
                    <ul>
                        <li>macOS 10.15 或更高版本</li>
                        <li>ARM64 架构 (M1/M2/M3 芯片)</li>
                        <li>至少 50MB 可用空间</li>
                    </ul>
                </div>
                <button class="download-btn" onclick="downloadFile('macos-arm64')">
                    <span class="status-indicator status-ready"></span>
                    下载 DMG 安装包
                </button>
                <div class="file-size">约 7.9MB</div>
            </div>

            <!-- Windows AMD64 -->
            <div class="download-card">
                <div class="platform-icon">🪟</div>
                <div class="platform-name">Windows (64位)</div>
                <div class="platform-desc">适用于 Intel 和 AMD 处理器的 Windows 电脑</div>
                <div class="download-info">
                    <h4>系统要求</h4>
                    <ul>
                        <li>Windows 10 或更高版本</li>
                        <li>64位处理器 (Intel/AMD)</li>
                        <li>至少 50MB 可用空间</li>
                    </ul>
                </div>
                <button class="download-btn" onclick="downloadFile('windows-amd64')">
                    <span class="status-indicator status-ready"></span>
                    下载 EXE 文件
                </button>
                <div class="file-size">约 16MB</div>
            </div>

            <!-- Windows ARM64 -->
            <div class="download-card">
                <div class="platform-icon">🪟</div>
                <div class="platform-name">Windows (ARM64)</div>
                <div class="platform-desc">适用于 ARM64 处理器的 Windows 电脑</div>
                <div class="download-info">
                    <h4>系统要求</h4>
                    <ul>
                        <li>Windows 10 ARM64 或更高版本</li>
                        <li>ARM64 处理器 (如 Surface Pro X)</li>
                        <li>至少 50MB 可用空间</li>
                    </ul>
                </div>
                <button class="download-btn" onclick="downloadFile('windows-arm64')">
                    <span class="status-indicator status-ready"></span>
                    下载 EXE 文件
                </button>
                <div class="file-size">约 15MB</div>
            </div>

            <!-- Linux AMD64 -->
            <div class="download-card">
                <div class="platform-icon">🐧</div>
                <div class="platform-name">Linux (64位)</div>
                <div class="platform-desc">适用于 Intel 和 AMD 处理器的 Linux 系统</div>
                <div class="download-info">
                    <h4>系统要求</h4>
                    <ul>
                        <li>主流 Linux 发行版</li>
                        <li>64位处理器 (Intel/AMD)</li>
                        <li>至少 50MB 可用空间</li>
                    </ul>
                </div>
                <button class="download-btn" onclick="downloadFile('linux-amd64')">
                    <span class="status-indicator status-ready"></span>
                    下载二进制文件
                </button>
                <div class="file-size">约 16MB</div>
            </div>

            <!-- Linux ARM64 -->
            <div class="download-card">
                <div class="platform-icon">🐧</div>
                <div class="platform-name">Linux (ARM64)</div>
                <div class="platform-desc">适用于 ARM64 处理器的 Linux 系统</div>
                <div class="download-info">
                    <h4>系统要求</h4>
                    <ul>
                        <li>主流 Linux 发行版</li>
                        <li>ARM64 处理器 (如树莓派4)</li>
                        <li>至少 50MB 可用空间</li>
                    </ul>
                </div>
                <button class="download-btn" onclick="downloadFile('linux-arm64')">
                    <span class="status-indicator status-ready"></span>
                    下载二进制文件
                </button>
                <div class="file-size">约 15MB</div>
            </div>
        </div>

        <div class="instructions">
            <h2>📋 安装说明</h2>
            
            <h3>macOS 用户</h3>
            <ol>
                <li>下载 DMG 文件后双击打开</li>
                <li>将 NavigationService.app 拖拽到 Applications 文件夹</li>
                <li>在 Finder 中打开 Applications 文件夹</li>
                <li>双击 NavigationService.app 启动服务</li>
                <li>在浏览器中访问 <code>http://localhost:8080</code></li>
            </ol>

            <h3>Windows 用户</h3>
            <ol>
                <li>下载对应的 EXE 文件</li>
                <li>双击 EXE 文件运行程序</li>
                <li>在浏览器中访问 <code>http://localhost:8080</code></li>
                <li>如需开机自启，可将 EXE 文件添加到启动项</li>
            </ol>

            <h3>Linux 用户</h3>
            <ol>
                <li>下载对应的二进制文件</li>
                <li>给文件添加执行权限：<code>chmod +x navigation-service-linux-*</code></li>
                <li>运行程序：<code>./navigation-service-linux-*</code></li>
                <li>在浏览器中访问 <code>http://localhost:8080</code></li>
            </ol>
        </div>
    </div>

    <script>
        function downloadFile(platform) {
            const button = event.target;
            const originalText = button.innerHTML;
            
            // 显示下载中状态
            button.innerHTML = '<span class="status-indicator status-building"></span>下载中...';
            button.disabled = true;
            
            // 开始下载
            const link = document.createElement('a');
            link.href = `/api/download/${platform}`;
            link.download = '';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            
            // 模拟下载完成
            setTimeout(() => {
                button.innerHTML = '<span class="status-indicator status-ready"></span>下载完成';
                setTimeout(() => {
                    button.innerHTML = originalText;
                    button.disabled = false;
                }, 2000);
            }, 1000);
        }

        // 检查文件可用性
        async function checkFileAvailability() {
            const platforms = ['macos-arm64', 'windows-amd64', 'windows-arm64', 'linux-amd64', 'linux-arm64'];
            
            for (const platform of platforms) {
                try {
                    const response = await fetch(`/api/download/check/${platform}`);
                    const data = await response.json();
                    
                    const button = document.querySelector(`[onclick="downloadFile('${platform}')"]`);
                    if (button) {
                        const indicator = button.querySelector('.status-indicator');
                        if (data.available) {
                            indicator.className = 'status-indicator status-ready';
                        } else {
                            indicator.className = 'status-indicator status-error';
                            button.disabled = true;
                            button.innerHTML = '<span class="status-indicator status-error"></span>文件不可用';
                        }
                    }
                } catch (error) {
                    console.error(`检查 ${platform} 文件失败:`, error);
                }
            }
        }

        // 页面加载时检查文件可用性
        document.addEventListener('DOMContentLoaded', checkFileAvailability);
    </script>
</body>
</html>
